package com.my.ecommercesystem.service.impl;


import com.my.ecommercesystem.dao.UserDao;
import com.my.ecommercesystem.entity.User;
import com.my.ecommercesystem.entity.UserAddress;
import com.my.ecommercesystem.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserDao userDao;

    public UserDao getUserDao() {
        return userDao;
    }

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    public List<User> getAllUser() {
        return userDao.queryAllUser();
    }

    @Override
    public User getUserById(Integer id) {
        return userDao.queryUserById(id);
    }

    @Override
    public boolean editUser(User user) {
        if(user!=null && user.getUser_id()!=null){
            return userDao.updateUser(user);
        }
        return false;
    }

    @Override
    public List<UserAddress> getAddressByUserId(Integer id) {
        return userDao.queryAddressByUserId(id);
    }

    @Override
    public boolean editAddressById(UserAddress address) {
        return userDao.updateAddressById(address);
    }

    @Override
    public boolean removeAddressById(Integer address_id) {
        return userDao.deleteAddressById(address_id);
    }

    @Override
    public List<UserAddress> getDefaultAddressByUserId(Integer user_id) {
        return userDao.queryDefaultAddressByUserId(user_id);
    }

    @Override
    public boolean addUserAddress(UserAddress userAddress) {
        return userDao.insertUserAdress(userAddress);
    }

    @Override
    public User login(String user_pwd, String user_phone) {
        return userDao.login(user_pwd, user_phone);
    }

    @Override
    public boolean insertUser(User user) {
        if (user.getUser_name()!=null&&user.getUser_phone()!=null&&user.getUser_pwd()!=null) {
            return userDao.insertUser(user);
        }
        return false;
    }

    @Override
    public User queryUserByPhone(String user_phone) {
        if (user_phone!=null){
            User user = userDao.queryUserByPhone(user_phone);
            return user;
        }
        return null;
    }
}
